import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/postParameter")
public class PostParameterServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 约定 前端构造这样的请求 ;
        // Post/ postParameter
        // Content-type : x-www-form-urlencoded
        // 键值对格式
        // username=xxx & password=xxxx ;
        //我们在后端把键值对的值拿到
        //获取值的方法一样是 getParameter() ;
        String username = req.getParameter("username") ;
        String password = req.getParameter("password") ;
        //打印 结果
        System.out.println("username:"+username+" password:"+password);
        resp.getWriter().write("ok");
    }
}
